﻿using VideoStore.Common.Enum;
using VideoStore.Domain.Entities;
using Warehouse.Services.Base;
using Warehouse.Services.Dto;

namespace Warehouse.Services.Translation
{
    public class DeliveryTranslator : BaseTranslator
    {
        #region Overrides of BaseTranslator

        /// <summary>
        /// Translates to concrete entity.
        /// </summary>
        /// <typeparam name="TDto">The type of the dto.</typeparam>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="dto">The dto.</param>
        /// <param name="concreteEntity">The concrete entity.</param>
        /// <returns></returns>
        public override TEntity TranslateToConcreteEntity<TDto, TEntity>(TDto dto, TEntity concreteEntity)
        {
            DeliveryDto tempDto = dto as DeliveryDto;
            if (tempDto != null)
            {
                Delivery tempEntity = concreteEntity as Delivery;
                if (tempEntity != null)
                {
                    tempEntity.id = tempDto.Id;
                    tempEntity.delivery_date = tempDto.DeliveryDate;
                    tempEntity.status = (int)tempDto.Status;
                    tempEntity.order_id = tempDto.OrderId;
                    tempEntity.warehouse_id = tempDto.WareHouseId;
                    return tempEntity as TEntity;
                }
            }
            return default(TEntity);
        }

        /// <summary>
        /// Translates to concrete dto.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <typeparam name="TDto">The type of the dto.</typeparam>
        /// <param name="entity">The entity.</param>
        /// <param name="concreteDto">The concrete dto.</param>
        /// <returns></returns>
        public override TDto TranslateToConcreteDto<TEntity, TDto>(TEntity entity, TDto concreteDto)
        {
            Delivery tempEntity = entity as Delivery;
            if (tempEntity != null)
            {
                DeliveryDto tempDto = concreteDto as DeliveryDto;
                if (tempDto != null)
                {
                    tempDto.Id = tempEntity.id;
                    tempDto.DeliveryDate = tempEntity.delivery_date;
                    tempDto.Status = (DeliveryStatus)tempEntity.status;
                    tempDto.OrderId = tempEntity.Order.id;
                    tempDto.WareHouseId = tempEntity.Warehouse.id;
                    return tempDto as TDto;
                }
            }
            return default(TDto);
        }

        #endregion
    }
}